{% extends request.ajax ? "layout_blank.phtml" : "layout_default.phtml" %}
{% import "macro_functions.phtml" as mf %}
{% set active_menu = 'support' %}
{% block meta_title %}Forum{% endblock %}

{% block content %}
<div class="widget simpleTabs">

    <ul class="tabs">
        <li><a href="#tab-index">{% trans 'Posts' %}</a></li>
        <li><a href="#tab-topics">{% trans 'Topics' %}</a></li>
        <li><a href="#tab-forums">{% trans 'Forums' %}</a></li>
        <li><a href="#tab-new">{% trans 'New topic' %}</a></li>
        <li><a href="#tab-new-forum">{% trans 'New forum' %}</a></li>
    </ul>

    <div class="tabs_container">

        <div class="fix"></div>
        
        <div class="tab_content nopadding" id="tab-index">
        {{ mf.table_search }}
        <table class="tableStatic wide">
            <thead>
                <tr>
                    <td colspan="2">{% trans 'Message' %}</td>
                    <td>{% trans 'Date' %}</td>
                    <td style="width: 13%">Actions</td>
                </tr>
            </thead>

            <tbody>
            {% set posts = admin.forum_message_get_list({"per_page":30, "page":request.page}|merge(request)) %}
            {% for i, post in posts.list %}
            <tr class="msg-id-{{post.id}}">
                <td style="width: 5%;"><a href="{{ 'forum/profile'|alink }}/{{post.author.id}}"><img src="{{  post.author.gravatar }}?size=20" alt="{{post.author.id}}" /></a></td>
                <td>
                    <a href="{{ 'forum/topic'|alink }}/{{post.forum_topic_id}}#msg-{{post.id}}" target="_blank">{{post.forum_title}}</a>
                    <br/>
                    {{ post.message|truncate(80) }}</td>
                <td>{{ post.created_at|timeago }} ago</td>
                <td class="actions">
                    <a class="bb-button btn14" href="{{ '/forum/topic'|alink }}/{{post.forum_topic_id}}#msg-{{post.id}}"><img src="images/icons/dark/pencil.png" alt=""></a>
                    <a class="bb-button btn14 bb-rm-tr api-link" href="{{ 'api/admin/forum/message_delete'|link({'id' : post.id})}}" data-api-confirm="Are you sure?"><img src="images/icons/dark/trash.png" alt=""></a>
                </td>
            </tr>
            
            {% else %}
                <tr>
                    <td colspan="4">
                        {% trans 'The list is empty' %}
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
        {% include "partial_pagination.phtml" with {'list': posts, 'url':'forum'} %}
        </div>
            
        <div class="tab_content nopadding" id="tab-topics">
            {{ mf.table_search }}
            <table class="tableStatic wide">
                <thead>
                    <tr>
                        <td style="width: 60%">{% trans 'Title' %}</td>
                        <td>{% trans 'Replies' %}</td>
                        <td>{% trans 'Views' %}</td>
                        <td>{% trans 'Status' %}</td>
                        <td>{% trans 'Sticky' %}</td>
                        <td style="width: 13%">Actions</td>
                    </tr>
                </thead>

                <tbody>
                {% set topics = admin.forum_topic_get_list({"per_page":30, "page":request.page}|merge(request)) %}
                {% for i, topic in topics.list %}

                <tr>
                    <td>{{ topic.forum.category }} > {{ topic.forum.title }} > {{ topic.title }}</td>
                    <td>{{ topic.stats.posts_count }}</td>
                    <td>{{ topic.stats.views_count }}</td>
                    <td>{{ mf.status_name(topic.status) }}</td>
                    <td>{{ mf.q(topic.sticky) }}</td>
                    <td class="actions">
                        <a class="bb-button btn14" href="{{ '/forum/topic'|alink }}/{{topic.id}}"><img src="images/icons/dark/pencil.png" alt=""></a>
                        <a class="bb-button btn14 bb-rm-tr api-link" href="{{'api/admin/forum/topic_delete'|link({'id' : topic.id}) }}" data-api-confirm="Are you sure?" data-api-redirect="{{ 'forum'|alink }}"><img src="images/icons/dark/trash.png" alt=""></a>
                    </td>
                </tr>
                {% else %}
                    <tr>
                        <td colspan="6">
                            {% trans 'The list is empty' %}
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
            {% include "partial_pagination.phtml" with {'list': topics, 'url':'forum'} %}
        </div>

        <div class="tab_content nopadding" id="tab-new">

            <form method="post" action="{{ 'api/admin/forum/topic_create'|link }}" class="mainForm save api-form" data-api-redirect="{{ 'forum'|alink }}">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{% trans 'Forum' %}:</label>
                        <div class="formRight">
                            {{ mf.selectbox('forum_id', admin.forum_get_pairs, request.forum_id, 1) }}
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Status' %}:</label>
                        <div class="formRight">
                            <input type="radio" name="status" value="active" checked="checked"/><label>{% trans 'Active' %}</label>
                            <input type="radio" name="status" value="locked" /><label>{% trans 'Locked' %}</label>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Sticky' %}:</label>
                        <div class="formRight">
                            <input type="radio" name="sticky" value="1" /><label>{% trans 'Yes' %}</label>
                            <input type="radio" name="sticky" value="0" checked="checked"/><label>{% trans 'No' %}</label>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Title' %}:</label>
                        <div class="formRight">
                            <input type="text" name="title" value="{{request.title}}" required="required" placeholder=""/>
                        </div>
                        <div class="fix"></div>
                    </div>
                    
                    <div class="rowElem">
                        <label>{% trans 'Message' %}</label>
                        <div class="formRight">
                            <textarea name="message" cols="5" rows="10">{{ request.message }}</textarea>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <input type="submit" value="{% trans 'Create' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>

        <div class="tab_content nopadding" id="tab-new-forum">

            <form method="post" action="{{ 'api/admin/forum/create'|link }}" class="mainForm save api-form" data-api-redirect="{{ 'forum'|alink }}">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{% trans 'Category' %}:</label>
                        <div class="formRight">
                            <input type="text" name="category" value="{{request.category}}" placeholder=""/>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Title' %}:</label>
                        <div class="formRight">
                            <input type="text" name="title" value="{{request.title}}" required="required" placeholder=""/>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Status' %}:</label>
                        <div class="formRight">
                            <input type="radio" name="status" value="active" checked="checked"/><label>{% trans 'Active' %}</label>
                            <input type="radio" name="status" value="locked" /><label>{% trans 'Locked' %}</label>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Description' %}</label>
                        <div class="formRight">
                            <textarea name="description" cols="5" rows="4">{{ request.description }}</textarea>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <input type="submit" value="{% trans 'Create' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
            <div class="fix"></div>
        </div>
        
        <div class="tab_content nopadding" id="tab-forums">
            <form method="post" action="{{ 'api/admin/forum/update_priority'|link }}" class="mainForm api-form" data-api-reload="1">
                <fieldset>
                    <table class="tableStatic wide">
                        <thead>
                            <tr>
                                <td style="width: 5%">{% trans 'Sorting' %}</td>
                                <td>{% trans 'Title' %}</td>
                                <td>{% trans 'Actions' %}</td>
                            </tr>
                        </thead>
                            
                        <tbody>
                        {% for category, forums in admin.forum_get_categories %}
                        <tr class="group">
                            <th colspan="3">{{category}}</th>
                        </tr>
                        {% for forum in forums %}
                        <tr>
                            <td><input type="text" name="priority[{{forum.id}}]" value="{{ forum.priority }}" style="width:30px;"></td>
                            <td>{{forum.title}}</td>
                            <td class="actions" style="width:13%">
                                <a class="bb-button btn14" href="{{ '/forum/'|alink }}/{{forum.id}}"><img src="images/icons/dark/pencil.png" alt=""></a>
                                <a class="bb-button btn14 bb-rm-tr api-link" href="{{'api/admin/forum/delete'|link({'id' : forum.id}) }}" data-api-redirect="{{ 'forum'|alink }}"><img src="images/icons/dark/trash.png" alt=""></a>
                            </td>
                        </tr>
                        {% endfor %}
                        {% endfor %}
                        </tbody>

                        <tfoot>
                            <tr>
                                <td colspan="3"></td>
                            </tr>
                        </tfoot>
                    </table>
                    <input type="submit" value="{% trans 'Update' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>
        
        <div class="fix"></div>
    </div>
</div>

{% endblock %}
